﻿/**************************************************************************
 *
 *
 *
 * 
 * ************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Newtonsoft.Json;
using System.Data.Entity.Migrations.Model;
using BLL;
using Model;
using System.Threading.Tasks;
using System.Web;
using System.IO;
using System.Net.Http.Headers;
using ValuationModel;
using System.Collections;
using System.Text;


namespace LandAppraisal.Controllers
{
    public class ValuesController : ApiController
    {
        EmployeeBLL empbll = new EmployeeBLL();

        #region 实现登录的方法
        /// <summary>
        /// 实现登录的方法
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>员工实体</returns>
        /// 
        Validte vld = new Validte();
        [HttpGet]
        public dynamic GetCodeImg(string t)
        {
            string code = vld.CreateRandomCode(4);
            byte[] imgByte = vld.CreateValidateGraphic(code);
            return new
            {
                code = code.ToLower(),
                imgByte = imgByte
            };
        }
        /// <summary>
        /// 验证码
        /// </summary>
        /// <param name="name"></param>
        /// <param name="password"></param>
        /// <param name="yzm"></param>
        /// <param name="LoginCode"></param>
        /// <returns></returns>
        public dynamic Get([FromUri]string name, string password, string yzm, string LoginCode)
        {
            var user = empbll.Login<SysUser>(name, password);
            if (yzm.ToString().ToUpper() == LoginCode.ToUpper().ToString())
            //判断验证码是否正确
            {
                if (user != null && user.ID != 0)
                {

                    return user;  //返回一个对象
                }
                else
                {
                    return null;//返回一个null
                }
            }
            return 1;//
        }
        #endregion

        #region 区位状况勘察
        /// <summary>
        ///区位状况勘察
        /// </summary>
        /// <param name="loca"></param>
        /// <returns></returns>
        [HttpPost]
        public int Post([FromBody] EALocation loca)
        {
            var ProjectNumber = loca.ProjectNumber;
            empbll.Update(ProjectNumber);
            return empbll.Add<EALocation>(loca);
        }
        #endregion

        #region 小区状况勘察
        /// <summary>
        /// 小区状况勘察
        /// </summary>
        /// <param name="village"></param>
        /// <returns></returns>
        [HttpPut]
        public int PUT([FromBody] EAVillage village)
        {
            village.Village_CreateTime = DateTime.Now;
            var ProjectNumber = village.ProjectNumber;
            empbll.Update(ProjectNumber);
            return empbll.Add<EAVillage>(village);
        }
        #endregion

        #region 楼况勘察
        /// <summary>
        /// 楼况勘察
        /// </summary>
        /// <param name="floors"></param>
        /// <returns></returns>
        [HttpPost]
        public int door([FromBody]EAFloors floors)
        {
            floors.Floor_CreateTime = DateTime.Now;
            floors.Floor_CreatePeople = "admin";
            var ProjectNumber = floors.ProjectNumber;
            empbll.Update(ProjectNumber);
            return empbll.Add<EAFloors>(floors);
        }
        #endregion

        #region 室内勘察
        /// <summary>
        /// 室内勘察
        /// </summary>
        /// <param name="indoor"></param>
        /// <returns></returns>
        [HttpPost]
        public int Indoor([FromBody] EAIndoor indoor)
        {
            var ProjectNumber = indoor.ProjectNumber;
            empbll.Update(ProjectNumber);
            return empbll.Add<EAIndoor>(indoor);
        }
        #endregion

        #region 添加询价信息
        /// <summary>
        /// 添加询价信息
        /// </summary>
        /// <param name="inquiry"></param>
        /// <returns></returns>
        [HttpPost]
        public int AddInquiry(EAInquiry inquiry)
        {
            inquiry.Inquiry_Time = System.DateTime.Now;
            return empbll.Add<EAInquiry>(inquiry);
        }
        #endregion

        #region 实现图片上传
        /// <summary>
        /// 实现图片上传
        /// </summary>
        /// <param name="photo"></param>
        /// <returns></returns>
        public int Upload(EAPhoto photo)
        {
            return empbll.Upload(photo);
        }
        #endregion

    }
}